package top.gaui.nurse.jjwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
 * @author Fujie_Zeng
 * @version 1.0
 * @date 2020/4/11 11:46
 */
@Getter
@Setter
public class JwtUtils {
        //签名
        private String key="nurse";

        public String creatJwt(Integer id){
            String id1=Integer.toString(id);
            JwtBuilder jwtBuilder= Jwts.builder().setId(id1)
                    .setIssuedAt(new Date())
                    .signWith(SignatureAlgorithm.HS256,key);
            String token = jwtBuilder.compact();
            return token;
        }
        public Claims parseJwt(String token){
            Claims claims= Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody();
            return claims;
        }
}
